let emClient = null;

//初始化EM-SDK对象
export const doInitEmSDK = () => {
  if (!window.em) 
      return;
  emClient = window.em;
}

export {emClient}

//判断是否是否支持EM接口
const judgeApiSupport = (apiname) => {
  return !!window.em;
}

//重置EM表单的头
export const resetEmElement = () => {
  if (judgeApiSupport("resetNavigation")) {
      emClient.ready(function(){
          emClient.resetNavigation({title: ''});
      });
  }
}

// 控制EM客户端顶部头信息
export const controlEmTopNav = (params = {}) => {
  document.title = params.title ?  params.title : "" ;//和飞信中走此段,和飞信不进下面if语句
  window.document.title = params.title ?  params.title : "" ;
  if (!judgeApiSupport("configNavigation")){
      return;
  }
  const nav = {
      'success': function (argument) {
          console.log('controlEmTopNav success', JSON.stringify(argument));
      },
      'fail': function (argument) {
          console.log('controlEmTopNav fail', JSON.stringify(argument));
      },
      'left': {},
      'right': {},
      'title': '',
      showCloseButton: true
  };
 
  emClient.ready(function(){
      if(params.title===undefined){
          params.title = "";
      }
      emClient.configNavigation({...nav, ...params});//微信中走此段
  });
}